<template>
	<view>
		<view class="formModel">
			<view class="cu-form-group">
				<view class="title">养殖场名</view>
				<input :placeholder="option.farm_name" disabled='true' name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">被指导人</view>
				<input :placeholder="option.farm_farmers" disabled='true' name="input"></input>
			</view> 
			<view class="cu-form-group">
				<view class="title">处理方式</view>
                <view>
				<picker @change="bindPickerChange" :value="index" :range="array" range-key="name">
					<view class="picker">{{index>-1?picker[index]:array[index].name}}</view>
				</picker>
				</view>
			</view>
		     <!-- 第三方处理 -->
			<template v-if="index == 0">
				<view class="cu-form-group">
					<view class="title">第三方名称</view>
					<input v-model="faeces_organization" name="input" placeholder="请输入第三方（合作社/公司）名称"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">第三方联系方式</view>
					<input v-model="feaces_organization_phone" name="input" type="number"  placeholder="请输入第三方联系方式"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">收运周期（天）</view>
					<input v-model="faeces_collector_cycle" name="input" type="number" placeholder="请输入收运周期天数"></input>
				</view>
			</template>
			
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				title: 'picker',
				picker: ['第三方处理', '自有土地消纳', '直排'],
				array: [{name:'第三方处理'},{name: '自有土地消纳'}, {name:'直排'}],
				index: 0,
				option:"",
				faeces_organization:'',
				feaces_organization_phone:'',
				faeces_collector_cycle:'',
				faeces_handle:''
			}
		},
		onLoad(option) {
			this.option = option
		},
		onNavigationBarButtonTap() {
			this.postGuidance();
		},
		methods:{
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value
			},
			//验证手机号
			isPhone(){
				let regex = {
				    mobile: /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/
				};
				return regex.mobile.test(this.feaces_organization_phone);
			},
			postGuidance(){
				switch (this.index){
					case 0:
					this.faeces_handle ="第三方处理";
					break;
					case 1:
					this.faeces_handle ="自有土地消纳";
					break;
					case 2:
					this.faeces_handle ="直排";
				}
				if(this.index ==0){
					if(!this.isPhone()){
					uni.showToast({
						title:'请输入正确的手机号',
						icon:"none"
					});
					return;
				}
				}
				uni.request({
					url:this.confige.webUrl+"/sysFaeces/sysFaecesAdd",
					data:{
						farm_id:this.option.farmId,
						faeces_handle:this.faeces_handle,
						faeces_organization:this.faeces_organization,
						feaces_organization_phone:this.feaces_organization_phone,
						faeces_collector_cycle:this.faeces_collector_cycle
					},
					method:"POST",
					header:{
						'X-Token':this.User.token
					},
					success: (res) => {
						console.log(res)
						if(res.data.code == 200){
							uni.showModal({
								title:"提示",
								showCancel:false,
								content:"已成功进行指导！",
							    success:(res)=> {
									if (res.confirm) {
									uni.redirectTo({
										url:"./farmerDetails?farmId="+this.option.farmId
									})
									} 
								}
							});
						}
						else if(res.data.code == 400){
							uni.showModal({
								title:"提示",
								showCancel:false,
								content:res.data.message,
							    success:(res)=> {
									if (res.confirm) {
									} 
								}
							});
						}
							
						
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	// @import "../../../common/uni.css";
	@import "../../../common/main.css";
	@import "../../../common/colorui/icon.css";
	@import "../../../common/global.less";
	.formModel{
	background-color:@backcolorthree;
	border-bottom:2rpx solid #eaeaea;
	.cu-form-group {
	.title {min-width: calc(4em + 15px);}		
	}
	}
	
</style>
